/* indent size: 2 */

module.exports = app => {
    const DataTypes = app.Sequelize;
  
    const Products_activitys = app.model.define('products_activitys', {
      id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        comment: '商品-活动_中间表id'
      },
      pid: {
        type: DataTypes.INTEGER,
        allowNull: true,
        comment: '商品id',
        references: {
            model: 'products',
            key: 'id'
          }
      },
      aid: {
        type: DataTypes.INTEGER,
        allowNull: true,
        comment: '活动表id',
        references: {
            model: 'activitys',
            key: 'id'
          }
      },
      createdAt: {
        type: DataTypes.DATE,
        allowNull: true,
        comment: '创建时间'
      },
      updatedAt: { 
        type: DataTypes.DATE,
        allowNull: true,
        comment: '更新时间'
      }
    }, {
      tableName: 'products_activitys'
    });
  
    Products_activitys.associate = function() {
      app.model.Products.belongsToMany(app.model.Activitys,
        {
          through: app.model.ProductsActivitys,
          foreignKey: "pid",
          otherKey: "aid"
        })
      app.model.Activitys.belongsToMany(app.model.Products,
        {
          through: app.model.ProductsActivitys,
          foreignKey: "aid",
          otherKey: "pid"
        })
  
    }
  
    return Products_activitys;
  };
  